package com.qf.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/testServlet")
public class TestServlet extends BaseServlet {
    public void select(HttpServletRequest req, HttpServletResponse resp){
        System.out.println("add");
        try {
            resp.getWriter().print("ajax");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String add(HttpServletRequest req, HttpServletResponse resp){
        System.out.println("add");
        return "redirect:/login.jsp";
    }
    public String update(HttpServletRequest req, HttpServletResponse resp){
        System.out.println("update");
        return "forward:/login.jsp";
    }
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        doPost(req,resp);
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String id = req.getParameter("id");
//        System.out.println(id);
//
//        //响应前端（转发与重定向）
//        //resp.sendRedirect("/login.jsp");
//        //req.getRequestDispatcher("/login.jsp").forward(req,resp);
//        //如果前端是ajax
//        resp.setCharacterEncoding("utf-8");
//        resp.setContentType("text/html;charset=utf-8");
//
//        resp.getWriter().print("这里是假的小米商城");
//    }
}
